﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using SelfService.Model.Models;


namespace SelfService.ViewModel.SysConfigVMs
{
    public partial class SysConfigListVM : BasePagedListVM<SysConfigView, SysConfigSearcher>
    {

        protected override IEnumerable<IGridColumn<SysConfigView>> InitGridHeader()
        {
            return new List<GridColumn<SysConfigView>>{
                this.MakeGridHeader(x => x.Key),
                this.MakeGridHeader(x => x.Value),
                this.MakeGridHeader(x => x.ValueType),
                this.MakeGridHeader(x => x.Description),
                this.MakeGridHeader(x => x.GroupName),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysConfigView> GetSearchQuery()
        {
            var query = DC.Set<SysConfig>()
                .CheckContain(Searcher.Key, x=>x.Key)
                .CheckContain(Searcher.Value, x=>x.Value)
                .CheckEqual(Searcher.GroupId, x=>x.GroupId)
                .Select(x => new SysConfigView
                {
				    ID = x.ID,
                    Key = x.Key,
                    Value = x.Value,
                    ValueType = x.ValueType,
                    Description = x.Description,
                    GroupName = x.Group.Name,
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

    public class SysConfigView : SysConfig{
        [Display(Name = "分组名称")]
        public String GroupName { get; set; }

    }
}
